#include "ros/ros.h"
#include "geometry_msgs/Twist.h"
 
void cmdVelCallback(const geometry_msgs::Twist::ConstPtr& msg) {
    // 处理接收到的速度指令
    ROS_INFO("Received Twist: Linear Velocity = %.2f, Angular Velocity = %.2f",
             msg->linear.x, msg->angular.z);
}
 
int main(int argc, char **argv) {
    // 初始化ROS节点
    ros::init(argc, argv, "cmd_vel_subscriber");
    ros::NodeHandle nh;
 
    // 创建订阅者，订阅cmd_vel话题
    ros::Subscriber cmd_vel_sub = nh.subscribe("cmd_vel", 10, cmdVelCallback);
 
    // 循环等待回调函数
    ros::spin();
 
    return 0;
}